import axios from "axios";
import { getCookie } from "@utils/cookie.js";

const http = axios.create({
  baseURL: "http://xawn.f3322.net:18180/",
  timeout: 3000,
});
//设置请求拦截器
http.interceptors.request.use(
  (config) => {
    //检测token是否存在携带令牌
    let token = getCookie("_token");
    token && (config.headers["Authorization"] = token);
    return config;
  },
  (error) => {
    return Promise.reject(error);
  }
);
//数据过滤
http.interceptors.response.use(
  (response) => {
    return Promise.resolve(response);
  },
  (error) => {
    return Promise.reject(error);
  }
);

export default http;
